package com.ruoyi.web.controller.community.cpc;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.community.domain.BaseNotice;
import com.ruoyi.community.domain.CpcMemberInfo;
import com.ruoyi.community.domain.SimpleNoticeContent;
import com.ruoyi.community.service.IBaseNoticeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 党建信息公告Controller
 *
 * @author ruoyi
 * @date 2021-12-16
 */
@RestController
@RequestMapping("/community/cpc/notice")
public class CpcNoticeController extends BaseController
{
    @Autowired
    private IBaseNoticeService baseNoticeService;

    /**
     * 新增党建公告
     */
    @Log(title = "党建公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseNotice baseNotice)
    {
        baseNotice.setSectionId("1");
        return toAjax(baseNoticeService.insertBaseNotice(baseNotice));
    }

    /**
     * 删除党建公告
     */
    @Log(title = "党建公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable String[] noticeIds)
    {
        return toAjax(baseNoticeService.deleteBaseNoticeByIds(noticeIds));
    }

    /**
     * 修改党建公告
     */
    @Log(title = "党建公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseNotice baseNotice)
    {
        return toAjax(baseNoticeService.updateBaseNotice(baseNotice));
    }

    /**
     * 获取id对应党建公告的详细内容
     */
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") String noticeId)
    {
        return AjaxResult.success(baseNoticeService.selectBaseNoticeById(noticeId));
    }

    /**
     * 查询党建公告列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseNotice baseNotice)
    {
        baseNotice.setSectionId("1");
        startPage();
        List<BaseNotice> list = baseNoticeService.selectBaseNoticeList(baseNotice);
        return getDataTable(list);
    }

    /**
     * 获得党建公告预览信息，不带图片，为管理端公告列表服务
     */
    @GetMapping("/preview_without_pic")
    public TableDataInfo previewWithoutPic(BaseNotice baseNotice)
    {
        baseNotice.setSectionId("1");
        startPage();
        List<BaseNotice> list = baseNoticeService.selectBaseNoticePreviewWithoutPic(baseNotice);
        return getDataTable(list);
    }

    /**
     * 获得党建公告预览信息，带首页缩略图，为小程序端公告列表服务
     */
    @GetMapping("/preview_with_pic")
//    public TableDataInfo previewWithPic(BaseNotice baseNotice)
    public List<BaseNotice> previewWithPic()
    {
        BaseNotice baseNotice = new BaseNotice();
        baseNotice.setSectionId("1");
        startPage();
        List<BaseNotice> list = baseNoticeService.selectBaseNoticePreviewWithPic(baseNotice);
        for (int i = 0; i < list.size(); i++) {
            BaseNotice baseNotice1 = list.get(i);
            if(baseNotice1.getTopStatus()==1 && baseNotice1.getPicUrl()==null){
                baseNotice1.setPicUrl("https://z3.ax1x.com/2021/05/12/gdymOx.jpg");
            }
        }
        return list;
//        return getDataTable(list);
    }
}
